package com.jboost.common.file.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.jboost.common.constant.CommonConstant;
import com.jboost.common.constant.EnumInterface;

/**
 *@ClassName
 *@Description 文件处理状态枚举
 *@Author cxn
 *@Date 2022-10-11
 *@Version
 **/
public enum FileHandleStatusEnum implements EnumInterface {
    // 处理状态：processing-处理中；success-处理成功；fail-处理失败
    //状态码0成功，1等待处理，2正在处理，3处理失败。
    AWAIT("processing", "视频同步中",1),
    PROCESSING("processing", "视频同步中",2),
    SUCCESS("success", "视频同步成功",0),
    FAIL("fail", "上传失败",3);

    FileHandleStatusEnum(String code, String desc, Integer value) {
        this.code = code;
        this.desc = desc;
        this.value = value;
    }

    @EnumValue
    @JsonValue    //标记响应json值
    private final String code;
    private final Integer value;
    private final String desc;

    public String getCode() {
        return code;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
    public static FileHandleStatusEnum getByCode(String code) {
        FileHandleStatusEnum[] enums = FileHandleStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if(enums[i].code.equals(code)){
                return enums[i];
            }
        }
        return null;
    }
    public static FileHandleStatusEnum getByValue(Integer value) {
        FileHandleStatusEnum[] enums = FileHandleStatusEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if(enums[i].value == value){
                return enums[i];
            }
        }
        return null;
    }
    public static String getDescByCode(String code) {
        FileHandleStatusEnum bitrate = FileHandleStatusEnum.getByCode(code);
        if(null == bitrate){
            return code;
        }
        return bitrate.getDesc();
    }

    @Override
    public String desc() {
        return this.desc;
    }

    @Override
    public Integer value() {
        return null;
    }

    @Override
    public String code() {
        return this.code;
    }


}
